import React, { Component } from 'react'
import './tree.scss'
import TreeNode from './tree-node'
import PropTypes from 'prop-types';
import TreeStore from './store'

export default class Tree extends Component {
  constructor (props) {
    super(props)
    this.state = {
      store: new TreeStore({
        data: props.data
      }),
      childrenNode: []
    }
  }

  getChildContext () {
    return {
      TreeRoot: this
    }
  }

  onCheckedChange (node, val) {
    this.state.store.setChecked(node, val)
    this.setState({})
  }

  render () {
    return (
      <div>
        <div>全选</div>
        <ul>
          {
            this.props.data.map((u, index) => {
              return(
                <TreeNode data={u} key={index}></TreeNode>
              )
            })
          }
          </ul>
      </div>
    )
  }

}

Tree.childContextTypes = {
  TreeRoot: PropTypes.any
}